﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;

namespace OCR
{
    /// <summary>
    /// 光电开关计数委托
    /// </summary>
    /// <param name="index"></param>
    /// <param name="count"></param>
    public delegate void dgOpticalSwitchCount(int index, int count);

    public class OpticalSwitch
    {
        /// <summary>
        /// 设备状态
        /// </summary>
        /// <returns></returns>
        [DllImport("FreqDLL.dll", EntryPoint = "GetPowerCount", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
        public static extern int GetPowerCount();
        /// <summary>
        /// 指定设备的状态
        /// </summary>
        /// <param name="Index">指定设备索引号，从1开始</param>
        /// <returns></returns>
        [DllImport("FreqDLL.dll", EntryPoint = "GetPower", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
        public static extern int GetPower(int Index);
        /// <summary>
        /// 设备1的状态
        /// </summary>
        /// <returns></returns>
        [DllImport("FreqDLL.dll", EntryPoint = "GetPower1", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
        public static extern int GetPower1();
        /// <summary>
        /// 设备2的状态
        /// </summary>
        /// <returns></returns>
        [DllImport("FreqDLL.dll", EntryPoint = "GetPower2", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
        public static extern int GetPower2();

        //频率相关
        [DllImport("FreqDLL.dll", EntryPoint = "GetFreqCount", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
        public static extern int GetFreqCount();
        [DllImport("FreqDLL.dll", EntryPoint = "GetFreq", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
        public static extern int GetFreq(int Index);
        [DllImport("FreqDLL.dll", EntryPoint = "GetFreq1", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
        public static extern int GetFreq1();
        [DllImport("FreqDLL.dll", EntryPoint = "GetFreq2", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
        public static extern int GetFreq2();

        /// <summary>
        /// 初始化计数，默认值为0
        /// </summary>
        [DllImport("FreqDLL.dll", EntryPoint = "InitCount", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
        public static extern void InitCount();
        [DllImport("FreqDLL.dll", EntryPoint = "GetCountCount", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
        public static extern int GetCountCount();
        /// <summary>
        /// 读取指定探头的计数
        /// </summary>
        /// <param name="Index">指定设备索引号，从1开始</param>
        /// <returns></returns>
        [DllImport("FreqDLL.dll", EntryPoint = "GetCount", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
        public static extern int GetCount(int Index);
        /// <summary>
        /// 读取探头1的计数
        /// </summary>
        /// <returns></returns>
        [DllImport("FreqDLL.dll", EntryPoint = "GetCount1", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
        public static extern int GetCount1();
        /// <summary>
        /// 读取探头2的计数
        /// </summary>
        /// <returns></returns>
        [DllImport("FreqDLL.dll", EntryPoint = "GetCount2", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
        public static extern int GetCount2();

        [DllImport("FreqDLL.dll", EntryPoint = "GetIDEx", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
        public static extern int GetIDEx(int Index, [MarshalAs(UnmanagedType.LPStr)]StringBuilder APChar,
            ref int APCharLen);
       
        /// <summary>
        /// 计数委托
        /// </summary>
        /// <param name="callback">委托函数</param>
        [DllImport("FreqDLL.dll", EntryPoint = "SetCount", CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)]
        public static extern void SetCount(dgOpticalSwitchCount callback);
    }
}
